package de.reichelt.fxrequi.data;

import de.reichelt.fx.FxOption;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Testpack {
  private final IntegerProperty id = new SimpleIntegerProperty();
  private final StringProperty projectName = new SimpleStringProperty();
  private final ObjectProperty<FxOption> kind = new SimpleObjectProperty<>();
  private final ObjectProperty<FxOption> method = new SimpleObjectProperty<>();
  private final StringProperty descr = new SimpleStringProperty();
  private final ObjectProperty<Date> dateCreated = new SimpleObjectProperty<>();
  private final StringProperty userCreated = new SimpleStringProperty();

  public static List<FxOption> kinds = Arrays.asList(new FxOption("ui", "Benutzeroberfläche"), 
          new FxOption("regr", "Regressionstest"), 
          new FxOption("load", "Lasttest"));
  public static List<FxOption> methods = Arrays.asList(new FxOption("man", "manuell"), 
          new FxOption("auto", "automatisch"));
  
  public Testpack() {
  }

  public Testpack(Integer id, String projectName, FxOption kind, FxOption method, 
          String descr, Date dateCreated, String userCreated) {
    setId(id);
    setProjectName(projectName);
    setKind(kind);
    setMethod(method);
    setDescr(descr);
    setDateCreated(dateCreated);
    setUserCreated(userCreated);
  }
  
  public int getId() {
    return id.get();
  }

  public void setId(int value) {
    id.set(value);
  }

  public IntegerProperty idProperty() {
    return id;
  }
  
  public String getProjectName() {
    return projectName.get();
  }

  public void setProjectName(String value) {
    projectName.set(value);
  }

  public StringProperty projectNameProperty() {
    return projectName;
  }
  
  public FxOption getKind() {
    return kind.get();
  }

  public void setKind(FxOption value) {
    kind.set(value);
  }

  public ObjectProperty<FxOption> kindProperty() {
    return kind;
  }
  
  public FxOption getMethod() {
    return method.get();
  }

  public void setMethod(FxOption value) {
    method.set(value);
  }

  public ObjectProperty<FxOption> methodProperty() {
    return method;
  }
  
  public String getDescr() {
    return descr.get();
  }

  public void setDescr(String value) {
    descr.set(value);
  }

  public StringProperty descrProperty() {
    return descr;
  }
  
  public Date getDateCreated() {
    return dateCreated.get();
  }

  public void setDateCreated(Date value) {
    dateCreated.set(value);
  }

  public ObjectProperty dateCreatedProperty() {
    return dateCreated;
  }
  
  public String getUserCreated() {
    return userCreated.get();
  }

  public void setUserCreated(String value) {
    userCreated.set(value);
  }

  public StringProperty userCreatedProperty() {
    return userCreated;
  }
  
  @Override
  public String toString() {
    return kind.get().getValue()+"-"+method.get().getValue();
  }
  
  public static FxOption getKind(String key) {
    for (FxOption opt: kinds) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getKindByValue(String value) {
    for (FxOption opt: kinds) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getMethod(String key) {
    for (FxOption opt: methods) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getMethodByValue(String value) {
    for (FxOption opt: methods) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
}
